package com.ruoyi.api.web;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.content.domain.Article;
import com.ruoyi.content.domain.Station;
import com.ruoyi.content.domain.Tag;
import com.ruoyi.content.service.IArticleService;
import com.ruoyi.content.service.IStationService;
import com.ruoyi.content.service.ITagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/content")
public class ContentApi extends BaseController {

    @Autowired
    private ITagService tagService;

    @Autowired
    private IArticleService articleService;

    @Autowired
    private IStationService stationService;

    @PostMapping("/tag")
    public TableDataInfo tagList(Tag tag){
        startPage();
        List<Tag> list = tagService.selectTagList(tag);
        return getDataTable(list);
    }

    @PostMapping("/article")
    public TableDataInfo article(Article article){
        startPage();
        article.setState("1");
        List<Article> list = articleService.selectArticleList(article);
        return getDataTable(list);
    }

    @PostMapping("/articleRan")
    public TableDataInfo articleRan(Article article){
        startPage();
        article.setState("1");
        List<Article> list = articleService.selectArticleTagListRan(article);
        return getDataTable(list);
    }

    @PostMapping("/article/{aid}")
    public Article article(@PathVariable("aid") Long aid){
        return articleService.selectArticleById(aid);
    }



    @PostMapping("/station")
    public TableDataInfo station(){
        startPage();
        List<Station> list = stationService.selectStationAllList(new Station());
        return getDataTable(list);
    }

    @PostMapping("/station/{sid}")
    public Station station(@PathVariable("sid") Long sid){
        return stationService.selectStationAllById(sid);
    }
}
